package com.halflife.comeElectricity.admin;

import org.apache.commons.lang.StringUtils;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by zhaoyf on 2018/3/4.
 */
public class NavStatic {
    public static String title(){
        return "";
    }
    public static String getDicCatagoryStr(String catagory){
       if ("charge".equals(catagory)) {
            return "缴费";
        }
        if ("deposit".equals(catagory)) {
            return "押金";
        }
        return "数据字典";
    }
    public static String active(String code, String path) {

        if (path.equals(code)) {
            return "active";
        }
        return "";
    }

    public static String active_pre(String code, String path) {
        if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(path)) {
            String key = path.split("\\.")[0].trim();
            String[] codes = code.split(",|，");
            for (String c : codes) {
                if (c.trim().equals(key)) {
                    return "active";
                }
            }
        }
        return "";
    }


    /**
     * 时间戳转化
     *
     * @param datenums
     * @return
     */
    public static String getDate(String datenums) {
        if (StringUtils.isBlank(datenums)) {
            return "";
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            Long datenum = Long.valueOf(datenums);
            if (datenum > 0) {

                Date d = new Date(datenum);
                String s = sdf.format(d);
                return s;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "--";
    }
    public static String getCommonDate(String datenums) {
        if (StringUtils.isBlank(datenums)) {
            return "";
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Long datenum = Long.valueOf(datenums);
            if (datenum > 0) {

                Date d = new Date(datenum);
                String s = sdf.format(d);
                return s;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "--";
    }
    public static String getDate(Long datenum) {
        if (datenum==null) {
            return "";
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            if (datenum > 0) {

                Date d = new Date(datenum);
                String s = sdf.format(d);
                return s;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "--";
    }
    public static String getCommonDate(Long datenum) {
        if (datenum==null) {
            return "";
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            if (datenum > 0) {

                Date d = new Date(datenum);
                String s = sdf.format(d);
                return s;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "--";
    }
    public static String getLong(Long datenum) {
        if (datenum==null) {
            return "";
        }


        return String.valueOf(datenum);
    }
    public static String getInteger(Integer datenum) {
        if (datenum==null) {
            return "";
        }


        return String.valueOf(datenum);
    }
    public static String getDouble(Double datenum) {
        if (datenum==null) {
            return "";
        }


        return String.valueOf(datenum);
    }

    public static String getBigDecimal(BigDecimal datenum) {
        if (datenum==null) {
            return "";
        }


        return String.valueOf(datenum.doubleValue());
    }

    /**
     * 时间戳转化
     *
     * @param datenum
     * @return
     */
    public static String getDate_(String datenum) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        try {
            if (Long.getLong(datenum) > 0) {

                Date d = new Date(datenum);
                String s = sdf.format(d);
                return s;
//            Calendar c = Calendar.getInstance();
//            c.setTimeInMillis(datenum);
//            int year = c.get(Calendar.YEAR);
//            int month = c.get(Calendar.MONTH);
//            int day = c.get(Calendar.DAY_OF_MONTH);
//            int hour = c.get(Calendar.HOUR_OF_DAY);//24小时制
//            int minute = c.get(Calendar.MINUTE);
//
//            return year + "-" + (month + 1) + "-" + day + " "
//                   + hour + ":" + minute;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "--";
    }
}
